/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>店铺拼团活动管理</h3>
        <h5>商城店铺拼团活动列表与管理</h5>
      </div>
    </div>
    <div
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>预售活动管理, 由总平台设置管理.</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>店铺预售活动列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input
          class="searchinput"
          v-model="title"
          width="10"
          size="small"
          placeholder="活动名称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column label="活动名称" prop="title" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="预售商品" prop="goods_name" width="150" show-overflow-tooltip></el-table-column>
        <el-table-column label="活动时间" prop="sell_time_show" width="300"></el-table-column>
        <el-table-column label="支付时间" prop="pay_time_show" width="300"></el-table-column>
        <el-table-column label="订购数量" prop="deposit_goods_num" width="90"></el-table-column>
        <el-table-column label="订单数" prop="deposit_order_num" width="90"></el-table-column>
        <el-table-column label="所属店铺" prop="store.store_name" width="120"></el-table-column>
        <el-table-column label="审核状态" prop="status_desc" width="90"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <el-button size="small" @click="detail(scope.row)" icon="el-icon-zoom-in">详情</el-button>
              <el-button
                size="small"
                @click="changeStatus(scope.row, 1)"
                v-if="scope.row.status == 0"
                icon="el-icon-check"
              >通过</el-button>
              <el-button
                size="small"
                @click="changeStatus(scope.row, 2)"
                v-if="scope.row.status == 0"
                icon="el-icon-close"
              >拒绝</el-button>
              <el-button
                size="small"
                @click="close(scope.row)"
                icon="el-icon-remove"
                v-if="scope.row.status == 1 && scope.row.sell_end_time > Date.parse(new Date()) / 1000"
              >取消</el-button>
              <el-button
                size="small"
                @click="orderData(scope.row)"
                icon="el-icon-tickets"
                v-if="scope.row.status == 1"
              >订单数据</el-button>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getPreSellPage, changePreSellStatus, closePreSell } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      title: null,
      status: null || this.$route.params.status
    };
  },
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getPreSellPage({
        title: this.title,
        status: this.status,
        page: this.currentPage,
        size: this.pageSize
      }).then(function(res) {
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message.success("刷新成功！");
    },
    detail(row) {
      this.$message.info("开发中。。。");
    },
    changeStatus(row, status) {
      var that = this;
      var prompt = status == 1 ? "通过？" : "拒绝？";
      var data = {
        pre_sell_id: row.pre_sell_id,
        status: status
      };
      this.$confirm("确认" + prompt, "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning"
      })
        .then(() => {
          changePreSellStatus(data).then(function(res) {
            if (res.status == 1) {
              that.getPage();
            }
          });
        })
        .catch(() => {});
    },
    orderData(row) {
      this.$message.info("开发中。。。");
    },
    close(row) {
      var that = this;
      this.$confirm("是否取消该活动?", "提示", {
        confirmButtonText: "是",
        cancelButtonText: "否",
        type: "warning"
      })
        .then(() => {
          closePreSell(row.pre_sell_id).then(function(res) {
            if (res.status == 1) {
              that.$message.success("取消成功!");
              that.getPage();
            }
          });
        })
        .catch(() => {});
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
